package com.example.ezexcel;

import cn.hutool.core.io.FileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.ezexcel.pojo.entity.QuestionData;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

@SpringBootApplication
public class EzexcelApplication {

    public static void main(String[] args) throws FileNotFoundException {

        /**
         * 判断d盘是否有excelFile目录，没有则创建
         */

        File dFiles = new File("d:/excelFile");
        if (!dFiles.exists()) {
            dFiles.mkdir();
        }

        /**
         *
         * 判断d盘是否有dbh2目录，没有则创建
         */
        File file = new File("d:/h2_exam");
        if (!file.exists()) {
            file.mkdir();
//             将resources目录下的dbh2下的所有文件复制到d:/dbh2目录下
//            File file1 = new File("src/main/resources/dbh2");
            // 获取jar包所在的目录
            System.err.println(System.getProperty("user.dir") );
            File file1 = new File(System.getProperty("user.dir") + "/h2_exam");
            System.err.println(file1.getPath());
            File[] files = file1.listFiles();
            //确保文件resources目录下的dbh2不会损坏
            for (File file2 : files) {
                // 用io流复制文件，FileInputStream读取，FileOutputStream写入
                FileInputStream fileInputStream = new FileInputStream(file2);
                //保证原始文件不会被损坏
                FileUtil.writeFromStream(fileInputStream, new File("d:/h2_exam/" + file2.getName()));
            }
        }

        SpringApplication.run(EzexcelApplication.class, args);
    }


}


